<script setup lang="ts">
import { getGoldMarket } from "@/api/quotation";
import { useTheme } from "@/composables/useTheme";
import { onLoad, onReady, onShow } from "@dcloudio/uni-app";
import { hidePageNavInWechatBrowser } from "@/composables/useHiddenNavbar";
import hideWechatMenu from "@/composables/hideWechatMenu";
onShow(() => {
  hideWechatMenu();
});
onReady(() => {
  hidePageNavInWechatBrowser();
});
let type = ref(1);
onLoad((option) => {
  if (option.type) {
    type.value = option.type; //1销售；2回购
  }
  getList();
});
let list = ref([]);
function getList() {
  getGoldMarket().then((res) => {
    let listData = res.data;
    if (!listData.length) return;
    listData.forEach((item) => {
      let list = [];
      for (const key in item.list) {
        list.push({
          id: key,
          name: item.list[key],
        });
      }
      item.list = list;
    });
    console.log(listData, "数据");

    list.value = listData;
  });
}
const { colorStyle } = useTheme();
function chooseHandler(item: any) {
  if (type.value == 1) {
    uni.$emit("chooseHandler", item);
  } else {
    uni.$emit("askChooseHandler", item);
  }

  uni.navigateBack();
}
</script>
<template>
  <view class="wrap" :style="colorStyle">
    <view class="data_item" v-for="(item, index) in list" :key="index">
      <view class="title">{{ item.title }}</view>
      <view class="info">
        <view
          class="switch_item pad2030 flex_sb"
          v-for="(_item, _index) in item.list"
          :key="_index"
          @click="chooseHandler(_item)"
        >
          <text>{{ _item.id + "-" + _item.name }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<style scoped lang="scss">
.wrap {
  .data_item {
    .title {
      color: rgba(125, 136, 140, 1);
      font-size: 28rpx;
      padding: 16rpx 30rpx;
    }
    .info {
      .switch_item {
        font-size: 30rpx;
        background: #fff;
        color: rgba(39, 38, 54, 1);
        &:not(:last-child) {
          margin-bottom: 2rpx;
        }
      }
    }
  }
}
</style>
